package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsAddress;
import com.qf.service.AddressService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/4 21:06
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/address")
public class Addresscontroller {

       @Autowired
       private   AddressService service;
       @RequestMapping("/list")
       public  Object list(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer limit,
                           String name, Integer userId, @RequestParam(defaultValue = "add_time") String sort,
                           @RequestParam(defaultValue = "desc") String order ){
           IPage<DtsAddress> list = service.list(page, limit, name, userId, sort, order);

           List<DtsAddress> records = list.getRecords();

           long total = list.getTotal();

           HashMap<String,Object> data = new HashMap<>();
            data.put("total", total);
            data.put("items", records);
           return ResponseUtil.ok(data);
       }

}
